import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import { findTagList, findTypeList } from '/@/api/blog/blog';
import { MarkDown } from '/@/components/Markdown';
import { h } from 'vue';

export const columns: BasicColumn[] = [
  {
    title: '标题',
    dataIndex: 'title',
    width: 200,
  },
  {
    title: '描述',
    dataIndex: 'summary',
    width: 180,
  },
  {
    title: '发布状态',
    dataIndex: 'status',
  },
  {
    title: '访问数',
    dataIndex: 'views',
  },
  {
    title: '评论数',
    dataIndex: 'comments',
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'roleNme',
    label: '角色名称',
    component: 'Input',
    colProps: { span: 8 },
  },
];

export const formSchema: FormSchema[] = [
  {
    field: 'id',
    label: '文章id',
    component: 'Input',
    show: false,
  },
  {
    field: 'title',
    label: '文章标题',
    required: true,
    component: 'Input',
  },
  {
    label: '摘要',
    field: 'summary',
    component: 'Input',
  },
  {
    label: '分类',
    field: 'typeId',
    component: 'ApiSelect',
    colProps: { span: 6 },
    componentProps: {
      api: findTypeList,
      labelField: 'name',
      valueField: 'id',
    },
    required: true,
  },
  {
    label: '标签',
    field: 'tagList',
    colProps: { span: 6 },
    component: 'ApiSelect',
    componentProps: {
      api: findTagList,
      mode: 'multiple',
      labelField: 'name',
      valueField: 'id',
    },
    required: true,
  },
  {
    field: 'isComment',
    label: '是否开启评论',
    colProps: { span: 4 },
    component: 'RadioButtonGroup',
    defaultValue: true,
    componentProps: {
      options: [
        { label: '是', value: true },
        { label: '否', value: false },
      ],
    },
  },
  {
    field: 'status',
    label: '是否发布',
    colProps: { span: 4 },
    component: 'RadioButtonGroup',
    defaultValue: true,
    componentProps: {
      options: [
        { label: '是', value: true },
        { label: '否', value: false },
      ],
    },
  },
  {
    field: 'isHot',
    label: '是否推荐',
    component: 'RadioButtonGroup',
    defaultValue: false,
    colProps: { span: 4 },
    componentProps: {
      options: [
        { label: '是', value: true },
        { label: '否', value: false },
      ],
    },
  },
  {
    field: 'context',
    component: 'Input',
    label: 'markdown',
    defaultValue: 'defaultValue',
    rules: [{ required: true, trigger: 'blur' }],
    render: ({ model, field }) => {
      return h(MarkDown, {
        value: model[field],
        onChange: (value: string) => {
          model[field] = value;
        },
      });
    },
  },
];
